package com.dongdongshop.controller;

import com.dongdongshop.constant.ResultConstant;
import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnums;
import com.dongdongshop.model.TbTypeTemplate;
import com.dongdongshop.service.SpecOptionService;
import com.dongdongshop.service.TemplateService;
import com.dongdongshop.vo.BrandVo;
import com.dongdongshop.vo.TemplateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("template")
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @Autowired
    private SpecOptionService specOptionService;

    @PostMapping
    public Result templateList(@RequestBody TemplateVo templateVo) {
        List<TemplateVo> templateVoList = templateService.templateList(templateVo);
        return Result.OK().setData(templateVoList);
    }

    @DeleteMapping
    public Result deleteTemplate(@RequestParam Long id) {
        templateService.deleteTemplate(id);
        return Result.OK();
    }

    @DeleteMapping("deleteall")
    public Result deleteallTbTypeTemplate(@RequestParam(value = "ids[]") List<Long> ids) {
        templateService.deleteallTbTypeTemplate(ids);
        return Result.response(ResultEnums.DELETE_SUCCESS);
    }

    //增加
    @PostMapping(value = "add")
    public Result add(@RequestBody TemplateVo vo){
        templateService.add(vo);
        return Result.OK();
    }

    //回显
    @PostMapping("toupdate")
    public Result toupdate(@RequestParam Long id) {
        TemplateVo templateVo=templateService.toupdate(id);
        return Result.OK().setData(templateVo);
    }

    @PutMapping("updateTemplate")
    public Result updateTemplate(@RequestBody TemplateVo templateVo) {
        templateService.updateTemplate(templateVo);
        return Result.OK();
    }




    //查询单个商品类型模板
    @PostMapping("showbyid")
    public Result showbyid(@RequestParam Long id){
        try {
            TbTypeTemplate tbTypeTemplate=templateService.showbyid(id);
            return Result.response(ResultEnums.SUCCESS).setData(tbTypeTemplate);
        }catch (Exception e) {
            return Result.ER();
        }
    }
}
